package main;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import musicchange.Metadata;
import musicchange.Pack;
import musicchange.Unpack;

public class Gui {

	private JFrame frmMuzykoogarniacz;
	JRadioButton rdbtnMetadata;
	JRadioButton rdbtnPack;
	JRadioButton rdbtnUnpack;
	private JTextField textPath;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Gui window = new Gui();
					window.frmMuzykoogarniacz.setVisible(true);

				} catch (Exception e) {
					e.printStackTrace();
				}

			}

		});
	}

	/**
	 * Create the application.
	 */
	public Gui() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmMuzykoogarniacz = new JFrame();
		frmMuzykoogarniacz.setTitle("Muzykoogarniacz");
		frmMuzykoogarniacz.setBounds(100, 100, 340, 225);
		frmMuzykoogarniacz.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JMenuBar menuBar = new JMenuBar();
		frmMuzykoogarniacz.setJMenuBar(menuBar);

		JMenu mnPlik = new JMenu("Plik");
		menuBar.add(mnPlik);

		/**
		 * otwiera okienko z wyborem katalogu
		 */
		JButton btnOpen = new JButton("Otworz");
		btnOpen.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JFileChooser dir = new JFileChooser();
				dir.setCurrentDirectory(new File("."));
				dir.setDialogTitle("Wybierz katalog");
				dir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				if (dir.showOpenDialog(dir) == JFileChooser.APPROVE_OPTION) {
					textPath.setText(dir.getCurrentDirectory().toString());
					System.out.println(dir.getCurrentDirectory());
				}
			}
		});

		btnOpen.setBorderPainted(false);
		btnOpen.setContentAreaFilled(false);

		rdbtnMetadata = new JRadioButton("Uzupelnij metadane");
		rdbtnMetadata.setBounds(12, 43, 314, 23);
		frmMuzykoogarniacz.getContentPane().add(rdbtnMetadata);

		rdbtnPack = new JRadioButton("Skataloguj");
		rdbtnPack.setBounds(12, 70, 314, 23);
		frmMuzykoogarniacz.getContentPane().add(rdbtnPack);

		rdbtnUnpack = new JRadioButton("Wypakuj z katalogow");
		rdbtnUnpack.setBounds(12, 96, 314, 23);
		frmMuzykoogarniacz.getContentPane().add(rdbtnUnpack);

		ButtonGroup group = new ButtonGroup();
		group.add(rdbtnMetadata);
		group.add(rdbtnPack);
		group.add(rdbtnUnpack);

		mnPlik.add(btnOpen);
		frmMuzykoogarniacz.getContentPane().setLayout(null);

		JButton btnDo = new JButton("Wykonaj");
		btnDo.setBounds(12, 138, 314, 25);
		frmMuzykoogarniacz.getContentPane().add(btnDo);

		textPath = new JTextField();
		textPath.setText("Podaj sciezke do katalogu");
		textPath.setBounds(12, 12, 314, 23);
		frmMuzykoogarniacz.getContentPane().add(textPath);
		textPath.setColumns(10);

		btnDo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (rdbtnMetadata.isSelected()) {
					System.out
							.println("uzupelnij metadane wszystkich plikow w folderze "
									+ textPath.getText());
					@SuppressWarnings("unused")
					Metadata meta = new Metadata(textPath.getText());
				}
				if (rdbtnPack.isSelected()) {
					System.out.println("skataloguj w folderze "
							+ textPath.getText());
					@SuppressWarnings("unused")
					Pack pack = new Pack(textPath.getText());
				}
				if (rdbtnUnpack.isSelected()) {
					System.out.println("wypakuj do folderu "
							+ textPath.getText());
					@SuppressWarnings("unused")
					Unpack unpack = new Unpack(textPath.getText());
				}
			}
		});

	}
}
